{extend name="common/base"}
{block name='title'}主页轮播图页面{/block}
{block name='body-type'}ad_index{/block}
{block name="content"}
        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">首页轮播图管理</div>


                            </div>
                            <div class="widget-body  am-fr">

                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" class="am-btn am-btn-default am-btn-success" onclick="window.location.href='add'"><span class="am-icon-plus"></span> 新增</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="am-u-sm-12">
                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                        <thead>
                                            <tr>
                                                <th>轮播图缩略图</th>
                                                <th>排序</th>
                                                <th>跳转地址</th>
                                                <th>描述</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="ajax-body">
                                            <!-- <tr class="gradeX">
                                                <td>轮播图缩略图</td>
                                                <td>排序</td>
                                                <td>跳转地址</td>
                                                <td>描述</td>
                                                <td>
                                                    <div class="tpl-table-black-operation">
                                                        <a href="{:Url('admin/ad/edit')}">
                                                            <i class="am-icon-pencil"></i> 编辑
                                                        </a>
                                                        <a href="{:Url('admin/ad/delete')}" class="tpl-table-black-operation-del">
                                                            <i class="am-icon-trash"></i> 删除
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr> -->
                                            <!-- more data -->
                                        </tbody>
                                    </table>
                                </div>
                                <div class="am-u-lg-12 am-cf">
                                    <div class="am-fr" id="ajax-page">
                                        {$page}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {/block}
        {block name="footer-js"}
        <script id="ajax-tpl" type="text/html">
            <%for (var i =0; i<data.length; i++){%>
            <tr class="gradeX">
                <td>
                    <img src="<%=data[i].thumb_src%>" class="tpl-table-line-img" alt="">
                </td>
                <td class="am-text-middle"><%=data[i].num%></td>
                <td class="am-text-middle"><%=data[i].link%></td>
                <td class="am-text-middle"><%=data[i].miaosu%></td>
                <td class="am-text-middle" style="width: 15%;">
                    <div class="tpl-table-black-operation">
                        <a href="{:Url('admin/ad/edit')}?id=<%=data[i].id%>">
                            <i class="am-icon-pencil"></i> 编辑
                        </a>
                        <a href="{:Url('admin/ad/delete')}?id=<%=data[i].id%>" class="tpl-table-black-operation-del">
                            <i class="am-icon-trash"></i> 删除
                        </a>
                    </div>
                </td>
            </tr>
            <%}%>
        </script>
        <script src="https://cdn.bootcss.com/template_js/0.7.1/template.min.js"></script>
        <script>
            //地址赋值
            $('#ajax-page a') .each(function () {
                $(this).attr('ajax-href' , $(this).attr('href'));
                $(this).removeAttr('href');
            })
            //将ajax转换成对象
            function ajax_request_content (obj) {
                $config = {
                    type: 'get',
                    success : function (res){
                    if (res.page != undefined) {
                        $('#ajax-page').html(res.page);
                        $('#ajax-page a') .each(function () {
                            $(this).attr('ajax-href' , $(this).attr('href'));
                            $(this).removeAttr('href');
                        })
                        var res = template(document.getElementById('ajax-tpl').innerHTML , {'data':res.adlist.data});
                        $('#ajax-body').html(res);
                    }
                }
                }
                if (obj != undefined){
                    //添加ajax传送地址
                    $config.url = obj.attr('ajax-href');//异步地址
                }
                //使用异步
                $.ajax($config)
            }
            //默认显示第一页
            ajax_request_content();
          //事件委托页码
            $('#ajax-page').on('click' , 'a',function () {
                var _this = $(this);
                ajax_request_content(_this);
            })
        </script>
        {/block}